﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuailDashboard.View.Web
{
    public static class LinqExtensions
    {
        public static IEnumerable<T> ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }

            return source;
        }

        public static IEnumerable<T> ForEach<T>(this IEnumerable<T> source, Action<T,int> action)
        {
            var idx = 0;
            foreach (var item in source)
            {
                action(item, idx);
                idx++;
            }

            return source;
        }

        public static string JoinStrings(this IEnumerable<string> strarr, string separator)
        {
            var result = string.Empty;

            foreach (var str in strarr)
            {
                if (result.Length > 0 && separator != null)
                    result += separator;
                result += str;
            }

            return result;
        }
    }
}